import random
import time,os
import uuid
from random import Random
from string import Template
import time
import json
import requests
from httprunner.api import HttpRunner

def sleep(n_secs):
    time.sleep(n_secs)

def deve_id():
    data = "ablkoyrtw65po"
    char_len = ""
    for i in range(0,6):
        char_len = char_len + data[random.randint(0,len(data)-1)]
    return str(char_len)

def get_search_key():
    data = [["你好","你好"],["hello","hello"],["123","123"]]
    return [data[Random().randint(0,3)]]
def get_validate_key():
    data = {"h": "ooo","b": {"c": "ccc"}}
    all_keys = data.keys()
    ss = ''.join(all_keys)
    print(ss)



AUTHORIZATION_PATH = r'data/authorization'
def generate_authorization():
    if (not os.path.exists(AUTHORIZATION_PATH)) or (
            3600 < int(time.time()) - int(
        os.path.getctime(AUTHORIZATION_PATH))):
        # authorization 文件不存在或最后修改时间超过 3600 秒(1 个小时)则重新登录
        runner = HttpRunner()
        runner.run(r'api/dev/get_access_token_api.yml')
    with open(AUTHORIZATION_PATH, 'r') as f:
        authorization: str = f.read()
    return authorization

def teardown_saveAuthorization(response: requests.Response):
    foo: dict = json.loads(response.text)
    bar: str = foo['access_token']
    # 保存 authorization 到文件给其他 api 调用
    with open(AUTHORIZATION_PATH, 'w') as f:
        f.write(bar)



# if __name__ == '__main__':
#     print(deve_id())
    # get_validate_key()
    # data = "ablkoyrtw65po"
    # char_len = ""
    # for i in range(0, 6):
    #     char_len = char_len + data[random.randint(0, len(data))]
    # print(str(char_len),len(data))